exports.domark = async (context) => {
    const cloud = context.cloud; 
    const {openId} = context
    const { shopId = "",itemId=""} = context.data
    if(!itemId || !shopId) {
      //校验参数
      return {  success: false,  data: "", message: "请传入正确的参数"  } 
    }
    try {
      //查询数据库商家的session信息
      const result = await cloud.db.collection('c_key').find({  
          name: 'session',  
      });
      if(result && result.length>0) {
        //查询到相关session
        const shopSession = result[0]?.[shopId]
        if(shopSession) {
          //查询到相关session，则调用打标接口
          const result = await context.cloud.topApi.invoke({
          api : 'taobao.opentrade.special.users.mark',
          data : {
            'hit':true,
            'open_user_ids':openId,
            'item_id':itemId,
            'sku_id':0,
            'status':'MARK',
            'limit_num':1,
            'session':shopSession
          },
          });  
          if(result && result?.result && result?.result>0) {
            //打标成功
            return {  success: true,  data: result, message: "请求成功"  };  
          }
        }
        return {  success: false,  data: e,message: "系统错误"  } 
      }
      return {  success: false,  data: "",message: "系统错误"  } 
    } catch (error) {
      return {  success: false,  data: e,message: "系统错误"  } 
    }
};


exports.main = async (context) => {  
  return 'hello world'; 
}; 